:art: get_course_field_default

huangqimin001 %!s(int64=4) %!d(string=hace) años
padre
commit
411f5833ec
Se han modificado 3 ficheros con 48 adiciones y 1 borrados
  1. 10 1
      api/course_field_views.py
  2. 2 0
      api/urls.py
  3. 36 0
      registration/models.py

+ 10 - 1
api/course_field_views.py

@@ -6,7 +6,16 @@ from django_response import response
6 6
 from paginator import pagination
7 7
 
8 8
 from api.wx_views import get_course_field_limit_scene_qrcode_url
9
-from registration.models import CourseRegisterFieldInfo
9
+from registration.models import CourseRegisterFieldInfo, CourseRegisterFieldPoolInfo
10
+
11
+
12
+def get_course_field_default(request):
13
+    fields = CourseRegisterFieldPoolInfo.objects.filter(status=True)
14
+    fields = [f.data for f in fields]
15
+
16
+    return response(data={
17
+        'fields': fields,
18
+    })
10 19
 
11 20
 
12 21
 def add_course_field(request):

+ 2 - 0
api/urls.py

@@ -38,6 +38,8 @@ urlpatterns += [
38 38
 ]
39 39
 
40 40
 urlpatterns += [
41
+    url(r'^course/field/default$', course_field_views.get_course_field_default, name='get_course_field_default'),
42
+
41 43
     url(r'^course/field/add$', course_field_views.add_course_field, name='add_course_field'),
42 44
     url(r'^course/field/update$', course_field_views.update_course_field, name='update_course_field'),
43 45
     url(r'^course/field/get$', course_field_views.get_course_field, name='get_course_field'),

+ 36 - 0
registration/models.py

@@ -92,6 +92,42 @@ class CourseInfo(BaseModelMixin):
92 92
         }
93 93
 
94 94
 
95
+class CourseRegisterFieldPoolInfo(BaseModelMixin):
96
+    INPUT = 'input'
97
+    SELECT = 'select'
98
+    FILE = 'file'
99
+
100
+    FIELD_TYPE_TUPLE = (
101
+        (INPUT, 'input'),
102
+        (SELECT, 'select'),
103
+        (FILE, 'file'),
104
+    )
105
+
106
+    # {
107
+    #     "type": "input",  # input, select, file
108
+    #     "name": "",
109
+    #     "options": ["男", "女"],  # type=select
110
+    # }
111
+    field_type = models.CharField(_('field_type'), max_length=8, choices=FIELD_TYPE_TUPLE, default=INPUT, help_text='字段类型')
112
+    field_name = models.CharField(_('field_name'), max_length=32, blank=True, null=True, help_text='字段名称')
113
+    field_options = JSONField(_('field_options'), default=[], blank=True, null=True, help_text='字段选择')
114
+
115
+    class Meta:
116
+        verbose_name = _('课程报名字段池信息')
117
+        verbose_name_plural = _('课程报名字段池信息')
118
+
119
+    def __unicode__(self):
120
+        return '%d' % self.pk
121
+
122
+    @property
123
+    def data(self):
124
+        return {
125
+            'type': self.field_type,
126
+            'name': self.field_name,
127
+            'options': self.field_options,
128
+        }
129
+
130
+
95 131
 class CourseRegisterFieldInfo(BaseModelMixin):
96 132
     field_id = ShortUUIDField(_('field_id'), max_length=32, blank=True, null=True, help_text='字段唯一标识', db_index=True, unique=True)
97 133